Fix blosc2 loading
authorAntonio Valentino <antonio.valentino@tiscali.it>
Thu, 26 Feb 2026 21:15:45 +0000 (21:15 +0000)
committerAntonio Valentino <antonio.valentino@tiscali.it>
Sat, 28 Feb 2026 18:08:45 +0000 (18:08 +0000)
Origin: https://github.com/PyTables/PyTables/pull/1306
Forwarded: not-needed

Gbp-Pq: Name 0008-Fix-blosc2-loading.patch

tables/__init__.py

index f54426539cec4949dfc825d6a55c73e4698b8e5d..5b6b8f4ad6c73601d56027fefd6a6cfd61e167e0 100644 (file)
@@ -9,42 +9,51 @@ to efficiently cope with extremely large amounts of data.
 
 
 # Load the blosc2 library:
-# 1. Without a path (default, only the filename)
-# 2. In site-packages/blosc2/lib/ (venv, conda env, or system Python; same one where this tables is running)
-# 3. In tables.libs/ sibling (delvewheel, Windows-only)
+# 1. In tables.libs/ sibling (delvewheel, Windows-only)
+# 2. In tables
+# 3. In site-packages/blosc2/lib/ (venv, conda env, or system Python; same one where this tables is running)
+# 4. Without a path (default, only the filename)
 def _load_blosc2():
     import ctypes
     import platform
     import sysconfig
     from pathlib import Path
 
-    search_paths = ("default", "site-packages", "delvewheel")
+    search_paths = (
+        # "delvewheel"
+        Path(__file__).parent.with_suffix(".libs"),
+        # tables package
+        Path(__file__).parent,
+        # "site-packages"
+        Path(sysconfig.get_path("platlib")) / "blosc2" / "lib",
+        # "site-packages" purelib - this should be redundant
+        Path(sysconfig.get_path("purelib")) / "blosc2" / "lib",
+        # "default"
+        "",
+    )
     platform_system = platform.system()
     ext = (
         "so"
         if platform_system == "Linux"
         else ("dylib" if platform_system == "Darwin" else "dll")
     )
-    lib_file = f"libblosc2.{ext}"
+    lib_name = "blosc2"
+    lib_file = f"lib{lib_name}.{ext}"
 
     for where in search_paths:
-        lib_path = (
-            Path(lib_file)
-            if where == "default"
-            else (
-                Path(__file__).parent.with_suffix(".libs")
-                if where == "delvewheel"
-                else Path(sysconfig.get_path("purelib")) / "blosc2" / "lib"
-            )
-            / lib_file
-        )
-        if where == "default" or lib_path.exists():
+        lib_path = Path(where) / lib_file
+        if where == "" or lib_path.exists():
             try:
                 ctypes.CDLL(str(lib_path))  # may be Path in Python 3.12+
                 return True
             except OSError:
                 pass
 
+    import ctypes.util
+
+    if ctypes.util.find_library(lib_name):
+        return True
+
     return False